package com.guotai.meet.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.guotai.meet.entity.UserSystem;
import com.guotai.meet.service.UserSystemService;
import com.guotai.meet.utils.ExcelUtil;

@Controller
@RequestMapping("/excel")
public class ExcelController {
	@Autowired
    private UserSystemService userService;
	
	@RequestMapping(value = "/exportExcel")
    public void exportExcel(HttpServletResponse response) throws Exception {
        String[] headers = {"ID","用户名", "姓名",  "所属公司"};
        String fileName = "国台会务人员表";
        
        List<UserSystem>  studentList = userService.queryUserList(new UserSystem());
		/*
		 * List<UserSystem> studentList = new ArrayList(); UserSystem user = new
		 * UserSystem(); user.setUserName("guandezhi"); user.setRealName("张三");
		 * user.setCompany("贵州国台");
		 * 
		 * user.setSex(1); studentList.add(user);
		 */
 
        Map<String, Object> studentMap = new HashMap<String, Object>();
        studentMap.put("headers", headers);
        studentMap.put("dataList", studentList);
        studentMap.put("fileName", fileName);
 
        List<Map> mapList = new ArrayList();
        mapList.add(studentMap);
        ExcelUtil.exportMultisheetExcel(fileName, mapList, response);
    }
 
    @RequestMapping(value = "/readExcel")
    public String readExcel() throws Exception {
        String filePath = "F:\\student.xls";
        List<Map<String, String>> mapList = ExcelUtil.readExcel(filePath, 0);
      //  log.info("mapList:" + mapList);
        return "success";
    }
 


}
